<div id="categoryList[module:moduleid]" class="categoryList_list">
</div>
<script type="text/javascript">
 var catList = [
 [subtemplate|Category.html|allcategories]
 {}
 ]

  function addCategories(listItem, id) {
   var first = true;
   var ul = null;
   $.each($.grep(catList, function(c, i) {
   return (c.parentId==id);}), function(i, v){
    if (first) {
     ul = $('<ul></ul>');
     listItem.append(ul);
     first=false;
    }
    addCategories(ul.append('<li><a href="' + v.link + '">' + v.text + ' (' + v.nrposts + ')</a></li>'), v.id);   
   });
  }

 $(document).ready(function () {
  addCategories($('#categoryList[module:moduleid]'), 0)
 });
</script>
